package com.hmall.order.web;

import com.hmall.order.pojo.Order;
import com.hmall.order.pojo.RequestParams;
import com.hmall.order.service.IOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/order")
@Slf4j
public class OrderController {

   @Autowired
   private IOrderService orderService;

   @GetMapping("/{id}")
   public Order queryOrderById(@PathVariable("id") Long orderId) {
      return orderService.getById(orderId);
   }

//   @PostMapping
//   public void createOrder(@RequestBody Order order) {
//      orderService.save(order);
//   }
   @PostMapping
   public Long createOrder(@RequestBody RequestParams requestParams){
      log.info("用户正在下订单，订单信息：{}",requestParams);
      Long id = orderService.createOrder(requestParams);
      log.info("订单创建成功，订单id：{}",id);
      return id;
   }
}
